<template>
  <div class="login">
    <div class="main">
      <div class="tabBody">
        <div class="tabMain" id="tabMain">
          <router-link to="/login">
            <div class="tab" :class="{ tabActive: isActive[0] }" tabIndex="0" @click="tabCheck($event)">登录</div>
          </router-link>
          <router-link to="/register">
            <div class="tab" :class="{ tabActive: isActive[1] }" tabIndex="1" @click="tabCheck($event)">注册</div>
          </router-link>
        </div>
      </div>
      <router-view></router-view>
    </div>
  </div>

</template>

<script>
  import api from '../../router/api'
  import '../../common/less/login.less'
  export default {
    name: 'login',
    data () {
      return {
        isActive: [true, false],
      }
    },
    methods: {
      tabCheck(e) {
        let $this = this;
        $this.isActive = [false, false];
        $this.isActive[e.target.tabIndex] = true;
      },
      tabWatch() {
        let $this = this;
        if ($this.$route.name == 'register') {
          $this.isActive = [false, false];
          $this.isActive[1] = true;
        } else {
          $this.isActive = [false, false];
          $this.isActive[0] = true;
        }
      }
    },
    watch: {
      "$route": "tabWatch"
    },
    mounted: function () {
      let $this = this;
      $this.tabWatch();
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

